# -*- coding: cp1252 -*-
import random
import string

from xmpp import *
from Queue import *
import Behaviour
import ACLParser
import Envelope
import ACLMessage
import BasicFipaDateTime
import XMLCodec
import DF
import Organization
import AID

class Bureaucracy(Organization.Organization):
    def __init__(self,agent, nick, name,password=None, goalList=[], agentList=[],contentLanguage="sl",create=True):
        self.units=0
        Organization.Organization.__init__(self,agent, nick, name, "Bureaucracy", goalList, agentList, contentLanguage,create)





    def setGoal(self,goalList):
        """
        Updates organization goals
        """
        if self.state=="unavailable":
            raise Organization.Unavailable
            return
        if not self.owner:
            raise Organization.NotAllowed
            return
        Organization.Organization.setGoal(self,goalList)




    def checkCreationPermission(self):
        if self.owner==True:
                return True
        else:
                return False



    def addUnit(self,unit):
        if self.state=="unavailable":
            raise Organization.Unavailable
            return
        if not self.checkCreationPermission():
            raise Organization.NotAllowed
            return
        if self.units==0:
            Organization.Organization.addUnit(self,unit)
            self.units=1
        else:
            raise Organization.NotAllowed
            return

    def destroy(self):
        if self.state=="unavailable":
            raise Organization.Unavailable
            return
        if not self.owner:
            raise Organization.NotAllowed
            return
        Organization.Organization.destroy(self)


